<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>注册</title>

</head>
<body>
    <%- include('head',{title:"注册"})%>
  <div class="page">
    <h2>注册 - form</h2>
    <form action="/users/zhuce"  method="POST" >
      <label for="username">
        <input type="text" id="username" name="username" placeholder="请输入用户名">
      </label>
      <label for="phone">
        <input type="text" id="phone" name="phone" placeholder="请输入手机号码">
      </label>
      <label for="email">
        <input type="text" id="email" name="email" placeholder="请输入邮箱">
      </label>
      <label for="password">
        <input type="password" id="password" name="password" placeholder="请输入密码">
      </label>
      <label >
        <button type="submit"> 提交 </button>
        <button type="reset"> 重置 </button>
      </label>
    </form>

    <h2>注册 - ajax</h2>
    <div  >
      <label for="username1">
        <input type="text" id="username1" name="username" placeholder="请输入用户名">
      </label>
      <label for="phone1">
        <input type="text1" id="phone1" name="phone" placeholder="请输入手机号码">
      </label>
      <label for="email1">
        <input type="text" id="email1" name="email" placeholder="请输入邮箱">
      </label>
      <label for="password1">
        <input type="password" id="password1" name="password" placeholder="请输入密码">
      </label>
      <label >
        <button type="button" id="submitbtn"> 提交数据 </button>
      </label>
    </div>
  </div>
  <%- include foot  %>

  <script>
    $("#submitbtn").on('click',function(){
       $.ajax({
         url:"/users/register",
         type:"POST",
         data:{
           username:$("#username1").val(),
           password:$("#password1").val(),
           email:$("#email1").val(),
           phone:$("#phone1").val(),
         },
         success:res=>{
           console.log(res)
           alert(res.msg)
           if(res.code==200){
             location.href = "/login?username="+$("#username1").val();
           }
         }
       })
    })
  </script>
</body>
</html>